import 'package:flutter/material.dart';
import 'package:syria_sports/core/app_export.dart';
import 'package:syria_sports/data/controllers/notes_controller.dart';
import '../presentation/coach_notes_page/models/note_model.dart';
import '../presentation/exercises/exercises_page/models/exercise.dart';
import '../widgets/custom_text_form_field.dart';


class AddNoteDialog extends StatefulWidget {
  final Exercise gymExercise;
  const AddNoteDialog({super.key, required this.gymExercise});

  @override
  State<AddNoteDialog> createState() => _AddNoteDialogState();
}

class _AddNoteDialogState extends State<AddNoteDialog> {
  TextEditingController noteController = TextEditingController();


  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return AlertDialog(
      shadowColor: Colors.grey,
      elevation: 16,
      scrollable: true,
      backgroundColor: Theme.of(context).colorScheme.secondary,
      title: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          const Text('إضافة ملاحظات المدرب'),
          Text(widget.gymExercise.name,style: theme.textTheme.titleSmall!.copyWith(color: Colors.orange),),
        ],
      ),
      content: SizedBox(
        height: MediaQuery.of(context).size.height/3,
        child: SingleChildScrollView(
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              CustomTextFormField(
                controller: noteController,
                textInputAction: TextInputAction.newline,
                maxLines: 10,
                hintText: "ادخل ملاحظاتك على تمرين اليوم",
                title: 'ملاحظات المدرب',
                fillColor: Theme.of(context).colorScheme.secondary,
                textInputType: TextInputType.multiline,
              ),
            ],

          ),

        ),
      ),
      actions: [
        TextButton(
          onPressed: () {
            if(noteController.text.isNotEmpty) {
              NoteModel note = NoteModel(
                noteId: '-1',
                text: noteController.text,
                exerciseId: widget.gymExercise.exerciseId??"",
            );
              addNote(note);
              Navigator.pop(context);
            }
          },
          child:  Text('إضافة',style :theme.textTheme.titleMedium),
        ),
        TextButton(
          onPressed: () {
            Navigator.of(context).pop(); // إغلاق الديالوج
          },
          child: Text('رجوع',style :theme.textTheme.titleMedium),
        ),
      ],
    );
  }


  void addNote(NoteModel note){
    NotesController.addNote(note).then((value){

    }).catchError((e){

    });

  }
}

